package com.yuncheng.spcyApi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.mapper.SpcyQyJbxxMapper;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.IpRateLimiterUtils;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.qy.TempQySccjVo;
import com.yuncheng.spcyApi.vo.qy.TempQyScpzVo;
import com.yuncheng.spcyApi.vo.qy.TempQyZjVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hua
 */
@Api(tags = "临时接口")
@RestController
@RequestMapping("/api/spzx-spcy/temp")
public class Test2Controller {

    @Resource
    private SpcyQyJbxxMapper spcyQyJbxxMapper;


    @GetMapping(value = "rateLimit")
    public HttpResult rateLimit(){

        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId(), "rateLimit")){
            return HttpResult.error("操作频繁！");
        }

        return HttpResult.ok();
    }

    @ApiOperation(value = "企业车间分页查询")
    @GetMapping(value = "queryQyCjPList")
    public HttpResult queryQyCjPList(PageVo pageVo){

        Page<TempQySccjVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<TempQySccjVo> pageList = spcyQyJbxxMapper.selectQySccjPageList(page, new TempQySccjVo());
        return HttpResult.ok(pageList);
    }

    @ApiOperation(value = "企业证件分页查询")
    @GetMapping(value = "queryQyZjPList")
    public HttpResult queryQyZjPList(PageVo pageVo){

        Page<TempQyZjVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<TempQyZjVo> pageList = spcyQyJbxxMapper.selectQyZjPageList(page, new TempQyZjVo());
        return HttpResult.ok(pageList);
    }

    @ApiOperation(value = "企业品种分页查询")
    @GetMapping(value = "queryQyPzPList")
    public HttpResult queryQyPzPList(PageVo pageVo){

        Page<TempQyScpzVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<TempQyScpzVo> pageList = spcyQyJbxxMapper.selectQyPzPageList(page, new TempQyScpzVo());
        return HttpResult.ok(pageList);
    }


}
